package com.serkol.ams.bean;


import com.serkol.component.LocalUtil;
import com.serkol.constant.ResultCode;
import com.serkol.constant.ResultConstant;
import lombok.ToString;

@ToString
public class Result {


    private int status = 501;


    private String msg;


    private boolean success;

    private Object data;

    public Result() {

    }
public  static Result instance(){
        return  new Result();
}
    public  static Result ok(){
        Result result=new Result();
        result.setStatus(ResultConstant.SUCSESS);
        return  result;
    }
    public  static Result ok(Object data){
        Result result=new Result();
        result.setData(data);
        result.setStatus(ResultConstant.SUCSESS);
        return  result;
    }
    public  static Result failure(){
        Result result=new Result();
        result.setStatus(ResultConstant.FAIL);
        return  result;
    }
    public  static Result failure(String msg){
        Result result=new Result();
        result.setMsg(msg);
        result.setStatus(ResultConstant.FAIL);
        return  result;
    }
    public  static Result failure(int status,String msg){
        System.out.println("Status:"+status);
        System.out.println("Msg:"+msg);
        Result result=new Result();
        result.setStatus(status);
        result.setMsg(msg);
      //  result.setStatus(ResultConstant.FAIL);
        return  result;
    }
    public  static Result failure(int status){
        Result result=new Result();
        result.setStatus(status);
        return  result;
    }
    public  static Result failureCode(int status,String msgkey){
        Result result=new Result();
        result.setStatus(status);
        result.setMsg(LocalUtil.get(msgkey));
        return  result;
    }
    public Result(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static Result code(ResultCode resultCode) {
        Result result=new Result();
        result.setStatus(resultCode.getCode());
        result.setMsg(LocalUtil.get(resultCode.getMsg()));
        return  result;

    }
    public Result(int status) {
        this.status = status;
    }

    public Result(boolean success1) {
        if (success1) {
            this.status = ResultConstant.SUCSESS;
        }
        this.success = success1;

    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
 /*       if (msg == null) {
        //    String s = localUtil.get("sys.error_502");
            msg =Constant.getInfo(this.status);
        }*/
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        if (ResultConstant.SUCSESS == status) {
            success = true;
        }
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

